Public Class MUKPOContainerScheduleExcel2
    Inherits System.Web.UI.Page

    Private SSRDataSet As ShippingStatusReportDS2

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        SSRDataSet = getData()
        ExportExcel2()
    End Sub

    Private Sub ExportExcel2()
        Dim sb As New System.Text.StringBuilder

        Response.Clear()
        Response.ContentType = "application/msexcel"
        Response.AddHeader("content-disposition", "attachment; filename=""ContainerSchedule" & "_" & Utilities.GetRandomFileName() & ".xls""")
        GenTable(sb)
        Response.Write(sb.ToString)
        Response.End()
    End Sub

    Private Sub GenTable(ByRef sb As System.Text.StringBuilder)

        ' Table tag
        sb.Append("<TABLE cellSpacing=1 cellPadding=3 width=""100%""  border=1>")

        Me.GenHeader(sb)
        Me.GenRows(sb)

        ' Table end tag
        sb.Append("</table>")
    End Sub

    Private Function PSFormatString(ByVal value As String) As String
        Try
            Return value
        Catch ex As Exception
            Return ""
        End Try
    End Function

    Private Function PSFormatDate(ByVal value As Date) As String
        Try
            If value = Date.MinValue Then
                Return ""
            End If

            Return value.ToString(Config.DateFormat) 'String.Format("=T(""{0:dd/MMM/yyyy}"")", value)
        Catch ex As Exception
            Return ""
        End Try
    End Function

    Private Function PSFormatNumber(ByVal value As Int32, ByVal length As Int32) As String
        Try
            Return String.Format("=T(""{0:D" & length.ToString & "}"")", value)
        Catch ex As Exception
            Return ""
        End Try
    End Function

    Private Sub GenHeader(ByRef sb As System.Text.StringBuilder)
        sb.Append("<tr style='font-weight: bold;height:40px; text-align:center'>")
        GenDataHeader(sb)
        sb.Append("</tr>")
    End Sub

    Private Sub GenDataHeader(ByRef sb As System.Text.StringBuilder)
        sb.Append("<td style='width:40px;'>Req</td>")
        sb.Append("<td>Cont. Tag</td>")
        sb.Append("<td style='width:80px;'>Order Date</td>")
        sb.Append("<td>Bulk</td>")
        sb.Append("<td>Size</td>")
        sb.Append("<td>Pack</td>")
        sb.Append("<td>Type</td>")
        sb.Append("<td>Supp</td>")
        sb.Append("<td>O/No</td>")
        sb.Append("<td>Primary</td>")
        sb.Append("<td>Con</td>")
        sb.Append("<td style='width:90px;'>Con Point</td>")
        sb.Append("<td>Responsible</td>")
        sb.Append("<td style='width:90px;'>PO In Opera </td>")
        sb.Append("<td style='width:50px;'>PI/SC</td>")
        sb.Append("<td>Acc No</td>")
        sb.Append("<td>Customer</td>")
        sb.Append("<td>Cust PO No</td>")
        sb.Append("<td>Final Destination</td>")
        sb.Append("<td>Arrival Port</td>")
        sb.Append("<td  style='align:left'>Description</td>")
        sb.Append("<td style='width:50px;'>Lag Days</td>")
        sb.Append("<td style='width:80px;'>Factory ETD</td>")
        sb.Append("<td>Target ETD</td>")
        sb.Append("<td style='width:50px;'>On Hold</td>")
        sb.Append("<td style='width:80px;'>Shipped Date</td>")
        sb.Append("<td>Shipping Line</td>")
        sb.Append("<td>Vessel</td>")
        sb.Append("<td>Container No</td>")
        sb.Append("<td style='width:80px;'>ETA</td>")
        sb.Append("<td>Wk</td>")
        sb.Append("<td style='width:50px;'>Cont Del</td>")
        sb.Append("<td style='width:50px;'>Pay Auth</td>")
        sb.Append("<td style='width:60px;'>P Payment</td>")
        sb.Append("<td style='width:50px;'>P Dep Value</td>")
        sb.Append("<td>P Inv Value</td>")
        sb.Append("<td>P Pay Date</td>")
        sb.Append("<td>Doc Received</td>")
        sb.Append("<td style='width:80px;'>Completed</td>")
        sb.Append("<td style='width:50px;'>S Invoice No</td>")
        sb.Append("<td style='width:50px;'>S Invoice Value</td>")
        sb.Append("<td >S Invoice Date</td>")
        sb.Append("<td >S Payment Due</td>")
        sb.Append("<td >S Invoice Paid</td>")
        sb.Append("<td style='width:50px;'>Debtor Days</td>")
        sb.Append("<td style='width:50px;'>Extra Credit Days</td>")
        sb.Append("<td style='width:50px;'>Lead Days</td>")
        sb.Append("<td>Supp.O/No</td>")
    End Sub

    Private Sub GenRows(ByRef sb As System.Text.StringBuilder)

        Dim row As ShippingStatusReportDS2.ShippingStatusReportRow
        Dim sl As CShippingLine

        For Each row In SSRDataSet.ShippingStatusReport.Rows
            sb.Append("<tr>")

            sl = New CShippingLine(row)

            GenDataCells(sb, sl)

            sb.Append("</tr>")
        Next

    End Sub

    Private Sub GenDataCells(ByRef sb As System.Text.StringBuilder, ByVal row As CShippingLine)
        sb.Append("<td style='text-align:center'>" & PSFormatNumber(row.REQ, 4) & "</td>")
        sb.Append("<td>" & PSFormatNumber(PSToInteger(IIf(row.IsSalesOrderNull, 0, row.SalesOrder)), 5) & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatDate(row.OrderDate) & "</td>")
        sb.Append("<td>" & Utilities.GetBulkMeaning(PSFormatString(row.BulkType)) & "</td>")
        sb.Append("<td>" & PSFormatString(row.ContainerSize) & "</td>")
        sb.Append("<td>" & Utilities.GetPackMeaning(PSFormatString(row.LP)) & "</td>")
        sb.Append("<td>" & Utilities.GetTypeMeaning(PSFormatString(row.PONo_Type)) & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatString(row.PONo_Supplier).PadLeft(3, "0"c) & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatNumber(row.PONo_Number, 3) & "</td>")
        sb.Append("<td>" & Utilities.GetPrimaryMeaning(PSFormatString(row.IsPrimary)) & "</td>")
        sb.Append("<td style='text-align:center'>" & IIf(row.PONo_ConsolidationIsNull, "", row.PONo_Consolidation).toString & "</td>")
        sb.Append("<td>" & PSFormatString(row.ConPoint) & "</td>")
        sb.Append("<td>" & PSFormatString(row.Responsible) & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatDate(row.POInOpera) & "</td>")
        sb.Append("<td>" & PSFormatString(row.PI) & "</td>")
        sb.Append("<td>" & PSFormatString(row.AccNo) & "</td>")
        sb.Append("<td>" & PSFormatString(row.CustomerOrLocation) & "</td>")
        sb.Append("<td>" & PSFormatString(row.CustPONo) & "</td>")
        sb.Append("<td>" & PSFormatString(row.FinalDestination) & "</td>")
        sb.Append("<td>" & PSFormatString(row.ArrivalPort) & "</td>")
        sb.Append("<td>" & PSFormatString(row.Description) & "</td>")
        sb.Append("<td>" & IIf(row.LagDaysIsNull, "", row.LagDays).toString() & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatDate(row.FactoryETD) & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatDate(row.TargetETD) & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatString(IIf(row.OnHold, "Yes", "").toString) & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatDate(row.ShippingDate) & "</td>")
        sb.Append("<td>" & PSFormatString(row.ShippingLine) & "</td>")
        sb.Append("<td>" & PSFormatString(row.Vessel) & "</td>")
        sb.Append("<td>" & PSFormatString(row.ContainerNo) & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatDate(row.ETA) & "</td>")
        sb.Append("<td style='text-align:center'>" & getWeek(row.ETA) & "</td>")
        sb.Append("<td>" & PSFormatDate(row.ContainerDeliveried) & "</td>")
        sb.Append("<td>" & PSFormatString(row.PayAuth) & "</td>")
        sb.Append("<td>" & PSFormatString(row.Payment) & "</td>")
        sb.Append("<td>" & IIf(row.IsPDepValueNull, "", row.PDepValue).toString() & "</td>")
        sb.Append("<td>" & IIf(row.IsInvValueNull, "", row.InvValue).toString() & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatDate(row.PayDate) & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatString(IIf(row.DocReceived, "Yes", "").toString) & "</td>")
        sb.Append("<td style='text-align:center'>" & PSFormatDate(row.CompletedDate) & "</td>")
        sb.Append("<td>" & IIf(row.IsSInvoicedNull, "", row.SInvoiced).toString() & "</td>")
        sb.Append("<td>" & IIf(row.IsSalesInvoiceValueNull, "", row.SalesInvoiceValue).toString() & "</td>")
        sb.Append("<td>" & PSFormatDate(row.SalesInvoiceDate) & "</td>")
        sb.Append("<td>" & PSFormatDate(row.SalesPaymentDue) & "</td>")
        sb.Append("<td>" & PSFormatDate(row.SInvoicedPd) & "</td>")
        If (row.IsSalesInvoiceDateNull OrElse row.IsSInvoicedPdNull) Then
            sb.Append("<td></td>")
        Else
            sb.Append("<td>" & CalculateDebtorDays(row.SalesInvoiceDate, row.SInvoicedPd) & "</td>")
        End If

        If (row.IsSalesPaymentDueNull OrElse row.IsSInvoicedPdNull) Then
            sb.Append("<td></td>")
        Else
            sb.Append("<td>" & CalculateExtraCreditDays(row.SalesPaymentDue, row.SInvoicedPd) & "</td>")
        End If

        If (row.IsOrderDateNull OrElse row.IsShippingDateNull) Then
            sb.Append("<td></td>")
        Else
            sb.Append("<td>" & CalculateLeadDays(row.OrderDate, row.ShippingDate) & "</td>")
        End If

        sb.Append("<td>" & PSFormatString(row.SuppOrderNo) & "</td>")
    End Sub

    Function getWeek(ByVal value As Date) As String
        Try
            Return PSFormatNumber(Utilities.GetWeek(value), 2)
        Catch ex As Exception
            Return ""
        End Try
    End Function

    Private Function getData() As ShippingStatusReportDS2
        Dim myIDs As String = Request.QueryString("ids")
        Dim mySQLAdapter As SqlClient.SqlDataAdapter
        Dim mySelectCmd As SqlClient.SqlCommand
        Dim myDataSet As ShippingStatusReportDS2
        Dim sbSelectQuery As New System.Text.StringBuilder
        Dim strQuery As String

        If myIDs <> "" Then
            myIDs = myIDs.TrimEnd(New Char() {","c})
            myIDs = myIDs.Replace(",", "','")
            myIDs = "('" & myIDs & "')"
            sbSelectQuery.Append("SELECT 	[ShippingStatusReport].[ID], [REQ],	[OrderDate], ")
            sbSelectQuery.Append("[ContainerSize],	[LP],	[PONo_Office],	[PONo_Type], [PONo_Supplier], ")
            sbSelectQuery.Append("[PONo_Number],	[IsPrimary],	[PONo_Consolidation],	[AccNo],	[CustomerOrLocation], ")
            sbSelectQuery.Append(" [FinalDestination],	[ShippingStatusReport].[Description],	[FactoryETD],	[ShippingDate], ")
            sbSelectQuery.Append(" [ShippingLine].Abbr as ShippingLine,	[Vessel],	[ContainerNo],	[ETA],	[Week], ")
            sbSelectQuery.Append(" [ArrivalPort],	[PI],	[Payment],	[DocReceived],	[CompletedDate],	[BulkType], ")
            sbSelectQuery.Append(" [ModifiedDate],	[BulkOrderNo],	[PayAuth],	[ContainerDeliveried],	[POInOpera],	[InvValue], ")
            sbSelectQuery.Append(" [PayDate],	[Remarks],	[SInvoiced],	[SuppOrderNo],	[OnHold],	[OfficeID],	[CustPONo], ")
            sbSelectQuery.Append(" [BulkOrderOfficeID], 	getdate() CurrentDate,	[SInvoicedPd], ")
            sbSelectQuery.Append(" (SELECT ConPoints.[Description] FROM ConPoints		WHERE ConPoints.ConPointID = Suppliers.ConPointID) ConPoint, ")
            sbSelectQuery.Append(" [ShippingLineID],	[PDepValue],	[SalesOrder],	[SalesInvoiceValue],	[SalesInvoiceDate], ")
            sbSelectQuery.Append(" [SalesPaymentDue],	[TargetETD],	[ShippingStatusReport].[IsArchived],	[ResponsibleID], ")
            sbSelectQuery.Append(" (SELECT [Name] FROM Responsibles WHERE Responsibles.[ResponsibleID] = [ShippingStatusReport].[ResponsibleID]) Responsible, ")
            sbSelectQuery.Append(" CASE WHEN [FactoryETDEnteredDate] IS NULL THEN NULL  Else  DateDiff(Day, OrderDate, [FactoryETDEnteredDate])	END AS LagDays	")
            sbSelectQuery.Append(" FROM SHIPPINGSTATUSREPORT  LEFT JOIN ShippingLine ON [ShippingStatusReport].ShippingLineID = ShippingLine.ID ")
            sbSelectQuery.Append(" LEFT JOIN Suppliers ON [ShippingStatusReport].PONo_Supplier = Suppliers.SupplierCode ")
            sbSelectQuery.AppendFormat(" WHERE [ShippingStatusReport].[ID] IN {0} ", myIDs)

            'strQuery = "SELECT [ShippingStatusReport].ID, REQ, OrderDate, ContainerSize, LP, PONo_Office," & _
            '    "PONo_Type, PONo_Supplier, PONo_Number, IsPrimary, PONo_Consolidation, AccNo, CustomerOrLocation, " & _
            '    "FinalDestination, Description, FactoryETD, ShippingDate, ShippingLine, Vessel, ContainerNo, " & _
            '    "ETA, Week, ArrivalPort, PI, Payment, DocReceived, CompletedDate, BulkType, ModifiedDate, " & _
            '    "InvValue, SalesOrder, CustPONo, " & _
            '    "(SELECT ConPoints.[Description] FROM ConPoints WHERE ConPoints.ConPointID = Suppliers.ConPointID) ConPoint, " & _
            '    "(SELECT [Name] FROM Responsibles 	WHERE Responsibles.[ResponsibleID] = [ShippingStatusReport].[ResponsibleID]) Responsible, " & _
            '    "POInOpera," & _
            '    " CASE WHEN [FactoryETDEnteredDate] IS NULL THEN NULL Else  DateDiff(Day, OrderDate, [FactoryETDEnteredDate]) END AS LagDays," & _
            '    "[TargetETD], " & _
            '    "[OnHold]," & _
            '    "[ContainerDeliveried]," & _
            '    "PayAuth, " & _
            '    "Payment, " & _
            '    "PDepValue, " & _
            '    "PayDate, " & _
            '    "SInvoiced , " & _
            '    "SalesInvoiceValue, " & _
            '    "SalesInvoiceDate, " & _
            '    "SalesPaymentDue, " & _
            '    "SInvoicedPd, " & _
            '    "SuppOrderNo, " & _
            '    "getDate() CurrentDate FROM SHIPPINGSTATUSREPORT LEFT JOIN ShippingLine sLine ON [ShippingStatusReport].ShippingLineID = sLine.ID " & _
            '    " LEFT JOIN Suppliers ON [ShippingStatusReport].PONo_Supplier = Suppliers.SupplierCode WHERE [ShippingStatusReport].[ID] IN " & myIDs

            Select Case RequestContext.POType
                Case 0
                    ' strQuery = strQuery + " ORDER BY REQ ASC, IsPrimary ASC "
                    sbSelectQuery.Append(" ORDER BY REQ ASC, IsPrimary ASC ")
                Case 1
                    'strQuery = strQuery + " ORDER BY PONo_Type ASC, REQ ASC, IsPrimary, PONo_Supplier  "
                    sbSelectQuery.Append(" ORDER BY PONo_Type ASC, REQ ASC, IsPrimary, PONo_Supplier  ")
                Case 2
                    'strQuery = strQuery + " ORDER BY FactoryETD, REQ, IsPrimary ASC "
                    sbSelectQuery.Append(" ORDER BY FactoryETD, REQ, IsPrimary ASC ")
                Case 3
                    'strQuery = strQuery + " ORDER BY CustomerOrLocation, CustPONo, FinalDestination, REQ, IsPrimary ASC "
                    sbSelectQuery.Append("  ORDER BY CustomerOrLocation, CustPONo, FinalDestination, REQ, IsPrimary ASC ")
                Case 4
                    'strQuery = strQuery + " ORDER BY ETA, REQ, IsPrimary ASC "
                    sbSelectQuery.Append(" ORDER BY ETA, REQ, IsPrimary ASC ")
                Case 5
                    'strQuery = strQuery + " ORDER BY PONo_Supplier, PONo_Number "
                    sbSelectQuery.Append(" ORDER BY PONo_Supplier, PONo_Number ")
                Case 6
                    'strQuery = strQuery + " ORDER BY ContainerDeliveried, REQ, IsPrimary ASC  "
                    sbSelectQuery.Append(" ORDER BY ContainerDeliveried, REQ, IsPrimary ASC  ")
                Case 7
                    'strQuery = strQuery + " ORDER BY CustomerOrLocation, [PI], REQ, IsPrimary ASC"
                    sbSelectQuery.Append(" ORDER BY CustomerOrLocation, [PI], REQ, IsPrimary ASC")
                Case 8
                    'strQuery = strQuery + " ORDER BY Conpoints.Description, REQ, IsPrimary ASC"
                    sbSelectQuery.Append(" ORDER BY Conpoints.Description, REQ, IsPrimary ASC")
                Case 9
                    'strQuery = strQuery + " ORDER BY SalesOrder, REQ, IsPrimary ASC"
                    sbSelectQuery.Append(" ORDER BY SalesOrder, REQ, IsPrimary ASC")
                Case 10
                    'strQuery = strQuery + " ORDER BY [SInvoiced], REQ, IsPrimary ASC"
                    sbSelectQuery.Append(" ORDER BY [SInvoiced], REQ, IsPrimary ASC")
                Case 11
                    'strQuery = strQuery + " ORDER BY [CustomerOrLocation], [SInvoiced], REQ, IsPrimary ASC"
                    sbSelectQuery.Append(" ORDER BY [CustomerOrLocation], [SInvoiced], REQ, IsPrimary ASC")
            End Select
            mySelectCmd = New SqlClient.SqlCommand(sbSelectQuery.ToString())
            mySelectCmd.Connection = New SqlClient.SqlConnection(Config.ConnectionString)

            mySQLAdapter = New SqlClient.SqlDataAdapter(mySelectCmd)
            mySQLAdapter.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "ShippingStatusReport", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ID", "ID"), New System.Data.Common.DataColumnMapping("REQ", "REQ"), New System.Data.Common.DataColumnMapping("OrderDate", "OrderDate"), New System.Data.Common.DataColumnMapping("ContainerSize", "ContainerSize"), New System.Data.Common.DataColumnMapping("LP", "LP"), New System.Data.Common.DataColumnMapping("PONo_Office", "PONo_Office"), New System.Data.Common.DataColumnMapping("PONo_Type", "PONo_Type"), New System.Data.Common.DataColumnMapping("PONo_Supplier", "PONo_Supplier"), New System.Data.Common.DataColumnMapping("PONo_Number", "PONo_Number"), New System.Data.Common.DataColumnMapping("IsPrimary", "IsPrimary"), New System.Data.Common.DataColumnMapping("PONo_Consolidation", "PONo_Consolidation"), New System.Data.Common.DataColumnMapping("CustomerOrLocation", "CustomerOrLocation"), New System.Data.Common.DataColumnMapping("Description", "Description"), New System.Data.Common.DataColumnMapping("FactoryETD", "FactoryETD"), New System.Data.Common.DataColumnMapping("ShippingDate", "ShippingDate"), New System.Data.Common.DataColumnMapping("ShippingLine", "ShippingLine"), New System.Data.Common.DataColumnMapping("Vessel", "Vessel"), New System.Data.Common.DataColumnMapping("ContainerNo", "ContainerNo"), New System.Data.Common.DataColumnMapping("ETA", "ETA"), New System.Data.Common.DataColumnMapping("Week", "Week"), New System.Data.Common.DataColumnMapping("ArrivalPort", "ArrivalPort"), New System.Data.Common.DataColumnMapping("PI", "PI"), New System.Data.Common.DataColumnMapping("Payment", "Payment"), New System.Data.Common.DataColumnMapping("DocReceived", "DocReceived"), New System.Data.Common.DataColumnMapping("CompletedDate", "CompletedDate"), New System.Data.Common.DataColumnMapping("BulkType", "BulkType"), New System.Data.Common.DataColumnMapping("ModifiedDate", "ModifiedDate"), New System.Data.Common.DataColumnMapping("ConPoint", "ConPoint"), New System.Data.Common.DataColumnMapping("Responsible", "Responsible"), New System.Data.Common.DataColumnMapping("POInOpera", "POInOpera"), New System.Data.Common.DataColumnMapping("LagDays", "LagDays"), New System.Data.Common.DataColumnMapping("OnHold", "OnHold"), New System.Data.Common.DataColumnMapping("ContainerDeliveried", "ContainerDeliveried"), New System.Data.Common.DataColumnMapping("PayAuth", "PayAuth"), New System.Data.Common.DataColumnMapping("PDepValue", "PDepValue"), New System.Data.Common.DataColumnMapping("PayDate", "PayDate"), New System.Data.Common.DataColumnMapping("SInvoiced", "SInvoiced"), New System.Data.Common.DataColumnMapping("SalesInvoiceValue", "SalesInvoiceValue"), New System.Data.Common.DataColumnMapping("SalesInvoiceDate", "SalesInvoiceDate"), New System.Data.Common.DataColumnMapping("SalesPaymentDue", "SalesPaymentDue"), New System.Data.Common.DataColumnMapping("SInvoicedPd", "SInvoicedPd"), New System.Data.Common.DataColumnMapping("SuppOrderNo", "SuppOrderNo")})})

            myDataSet = New ShippingStatusReportDS2

            If mySQLAdapter.Fill(myDataSet) > 0 Then
                Return myDataSet
            Else
                Return Nothing
            End If
        End If

        Return Nothing
    End Function

    Protected Function CalculateDebtorDays(ByVal salesInvoiceDate As DateTime, ByVal sInvoicedPd As DateTime) As String
        Return MIMS.WRS.Entities.ShippingStatusReport.CalculateDebtorDays(CType(salesInvoiceDate, DateTime), CType(sInvoicedPd, DateTime)).ToString()
    End Function

    Protected Function CalculateExtraCreditDays(ByVal sPaymentDue As DateTime, ByVal sInvoicedPd As DateTime) As String
        Return MIMS.WRS.Entities.ShippingStatusReport.CalculateExtraCreditDays(CType(sPaymentDue, DateTime), CType(sInvoicedPd, DateTime)).ToString()
    End Function

    Protected Function CalculateLeadDays(ByVal orderDate As DateTime, ByVal shippingDate As DateTime) As String
        Return MIMS.WRS.Entities.ShippingStatusReport.CalculateLeadDays(CType(orderDate, DateTime), CType(shippingDate, DateTime)).ToString()
    End Function

    Private Function PSObject(ByVal value As Object) As String
        Try
            Return CType(value, String)
        Catch ex As Exception
            Return ""
        End Try
    End Function

    Private Function PSToInteger(ByVal value As Object) As Int32
        Try
            Return CType(value, Int32)
        Catch ex As Exception
            Return 0
        End Try
    End Function

    Protected Class CShippingLine

        Private m_Row As ShippingStatusReportDS2.ShippingStatusReportRow

        Public Sub New(ByVal row As ShippingStatusReportDS2.ShippingStatusReportRow)
            m_Row = row
        End Sub

#Region "   Data Properties"
        Protected ReadOnly Property DataRow() As ShippingStatusReportDS2.ShippingStatusReportRow
            Get
                Return m_Row
            End Get
        End Property

        Public ReadOnly Property ID() As System.Int32
            Get
                Return Me.DataRow.ID
            End Get
        End Property

        Public Property REQ() As System.Int32
            Get
                Return Me.DataRow.REQ
            End Get
            Set(ByVal Value As System.Int32)
                Me.DataRow.REQ = Value
            End Set
        End Property

        Public Property OrderDate() As System.DateTime
            Get
                If Me.DataRow.IsOrderDateNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.OrderDate
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetOrderDateNull()
                Else
                    Me.DataRow.OrderDate = Value
                End If
            End Set
        End Property

        Public ReadOnly Property IsOrderDateNull() As Boolean
            Get
                Return Me.DataRow.IsOrderDateNull
            End Get
        End Property

        Public Property ContainerSize() As System.String
            Get
                If Me.DataRow.IsContainerSizeNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.ContainerSize
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetContainerSizeNull()
                Else
                    Me.DataRow.ContainerSize = Value
                End If
            End Set
        End Property

        Public Property LP() As System.String
            Get
                If Me.DataRow.IsLPNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.LP
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetLPNull()
                Else
                    Me.DataRow.LP = Value
                End If
            End Set
        End Property

        Public Property PONo_Office() As System.String
            Get
                Return Me.DataRow.PONo_Office
            End Get
            Set(ByVal Value As System.String)
                Me.DataRow.PONo_Office = Value
            End Set
        End Property

        Public Property PONo_Type() As System.String
            Get
                Return Me.DataRow.PONo_Type
            End Get
            Set(ByVal Value As System.String)
                Me.DataRow.PONo_Type = Value
            End Set
        End Property

        Public Property PONo_Supplier() As System.String
            Get
                Return Me.DataRow.PONo_Supplier
            End Get
            Set(ByVal Value As System.String)
                Me.DataRow.PONo_Supplier = Value
            End Set
        End Property

        Public Property PONo_Number() As System.Int32
            Get
                Return Me.DataRow.PONo_Number
            End Get
            Set(ByVal Value As System.Int32)
                Me.DataRow.PONo_Number = Value
            End Set
        End Property

        Public Property IsPrimary() As System.String
            Get
                If Me.DataRow.IsIsPrimaryNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.IsPrimary
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetIsPrimaryNull()
                Else
                    Me.DataRow.IsPrimary = Value
                End If
            End Set
        End Property

        Public ReadOnly Property PONo_ConsolidationIsNull() As Boolean
            Get
                Return Me.DataRow.IsPONo_ConsolidationNull
            End Get
        End Property

        Public Property PONo_Consolidation() As System.Int32
            Get
                If Me.DataRow.IsPONo_ConsolidationNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.PONo_Consolidation
                End If
            End Get
            Set(ByVal Value As System.Int32)
                If Value = Nothing Then
                    Me.DataRow.SetPONo_ConsolidationNull()
                Else
                    Me.DataRow.PONo_Consolidation = Value
                End If
            End Set
        End Property

        Public Property AccNo() As System.String
            Get
                If Me.DataRow.IsAccNoNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.AccNo
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetAccNoNull()
                Else
                    Me.DataRow.AccNo = Value
                End If
            End Set
        End Property

        Public Property CustomerOrLocation() As System.String
            Get
                If Me.DataRow.IsCustomerOrLocationNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.CustomerOrLocation
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetCustomerOrLocationNull()
                Else
                    Me.DataRow.CustomerOrLocation = Value
                End If
            End Set
        End Property

        Public Property FinalDestination() As System.String
            Get
                If Me.DataRow.IsFinalDestinationNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.FinalDestination
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetFinalDestinationNull()
                Else
                    Me.DataRow.FinalDestination = Value
                End If
            End Set
        End Property

        Public Property Description() As System.String
            Get
                If Me.DataRow.IsDescriptionNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.Description
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetDescriptionNull()
                Else
                    Me.DataRow.Description = Value
                End If
            End Set
        End Property

        Public Property FactoryETD() As System.DateTime
            Get
                If Me.DataRow.IsFactoryETDNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.FactoryETD
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetFactoryETDNull()
                Else
                    Me.DataRow.FactoryETD = Value
                End If
            End Set
        End Property

        Public Property ShippingDate() As System.DateTime
            Get
                If Me.DataRow.IsShippingDateNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.ShippingDate
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetShippingDateNull()
                Else
                    Me.DataRow.ShippingDate = Value
                End If
            End Set
        End Property

        Public ReadOnly Property IsShippingDateNull() As Boolean
            Get
                Return Me.DataRow.IsShippingDateNull
            End Get
        End Property

        Public Property ShippingLine() As System.String
            Get
                If Me.DataRow.IsShippingLineNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.ShippingLine
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetShippingLineNull()
                Else
                    Me.DataRow.ShippingLine = Value
                End If
            End Set
        End Property

        Public Property Vessel() As System.String
            Get
                If Me.DataRow.IsVesselNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.Vessel
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetVesselNull()
                Else
                    Me.DataRow.Vessel = Value
                End If
            End Set
        End Property

        Public Property ContainerNo() As System.String
            Get
                If Me.DataRow.IsContainerNoNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.ContainerNo
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetContainerNoNull()
                Else
                    Me.DataRow.ContainerNo = Value
                End If
            End Set
        End Property

        Public Property ETA() As System.DateTime
            Get
                If Me.DataRow.IsETANull Then
                    Return Nothing
                Else
                    Return Me.DataRow.ETA
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetETANull()
                Else
                    Me.DataRow.ETA = Value
                End If
            End Set
        End Property

        Public Property Week() As System.Int32
            Get
                If Me.DataRow.IsWeekNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.Week
                End If
            End Get
            Set(ByVal Value As System.Int32)
                If Value = Nothing Then
                    Me.DataRow.SetWeekNull()
                Else
                    Me.DataRow.Week = Value
                End If
            End Set
        End Property

        Public Property ArrivalPort() As System.String
            Get
                If Me.DataRow.IsArrivalPortNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.ArrivalPort
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetArrivalPortNull()
                Else
                    Me.DataRow.ArrivalPort = Value
                End If
            End Set
        End Property

        Public Property PI() As System.String
            Get
                If Me.DataRow.IsPINull Then
                    Return Nothing
                Else
                    Return Me.DataRow.PI
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetPINull()
                Else
                    Me.DataRow.PI = Value
                End If
            End Set
        End Property

        Public Property Payment() As System.String
            Get
                If Me.DataRow.IsPaymentNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.Payment
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetPaymentNull()
                Else
                    Me.DataRow.Payment = Value
                End If
            End Set
        End Property

        Public Property DocReceived() As System.Boolean
            Get
                If Me.DataRow.IsDocReceivedNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.DocReceived
                End If
            End Get
            Set(ByVal Value As System.Boolean)
                If Value = Nothing Then
                    Me.DataRow.SetDocReceivedNull()
                Else
                    Me.DataRow.DocReceived = Value
                End If
            End Set
        End Property

        Public Property CompletedDate() As System.DateTime
            Get
                If Me.DataRow.IsCompletedDateNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.CompletedDate
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetCompletedDateNull()
                Else
                    Me.DataRow.CompletedDate = Value
                End If
            End Set
        End Property

        Public Property BulkType() As System.String
            Get
                If Me.DataRow.IsBulkTypeNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.BulkType
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetBulkTypeNull()
                Else
                    Me.DataRow.BulkType = Value
                End If
            End Set
        End Property

        Public Property ModifiedDate() As System.DateTime
            Get
                Return Me.DataRow.ModifiedDate
            End Get
            Set(ByVal Value As System.DateTime)
                Me.DataRow.ModifiedDate = Value
            End Set
        End Property

        Public Property CurrentDate() As System.DateTime
            Get
                Return Me.DataRow.CurrentDate
            End Get
            Set(ByVal Value As System.DateTime)
                Me.DataRow.CurrentDate = Value
            End Set
        End Property

        Public ReadOnly Property IsSalesOrderNull() As Boolean
            Get
                Return Me.DataRow.IsSalesOrderNull
            End Get
        End Property

        Public Property SalesOrder() As System.Int32
            Get
                If Me.DataRow.IsSalesOrderNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.SalesOrder
                End If
            End Get
            Set(ByVal Value As System.Int32)
                If Value = Nothing Then
                    Me.DataRow.SetSalesOrderNull()
                Else
                    Me.DataRow.SalesOrder = Value
                End If
            End Set
        End Property

        Public Property CustPONo() As System.String
            Get
                If Me.DataRow.IsCustPONoNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.CustPONo
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetCustPONoNull()
                Else
                    Me.DataRow.CustPONo = Value
                End If
            End Set
        End Property

        Public ReadOnly Property IsInvValueNull() As Boolean
            Get
                Return Me.DataRow.IsInvValueNull
            End Get
        End Property

        Public Property InvValue() As System.Decimal
            Get
                If Me.DataRow.IsInvValueNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.InvValue
                End If
            End Get
            Set(ByVal Value As System.Decimal)
                If Value = Nothing Then
                    Me.DataRow.SetInvValueNull()
                Else
                    Me.DataRow.InvValue = Value
                End If
            End Set
        End Property

        Public Property ConPoint() As System.String
            Get
                If Me.DataRow.IsConPointNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.ConPoint
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetConPointNull()
                Else
                    Me.DataRow.ConPoint = Value
                End If
            End Set
        End Property

        Public Property Responsible() As System.String
            Get
                If Me.DataRow.IsResponsibleNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.Responsible
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetResponsibleNull()
                Else
                    Me.DataRow.Responsible = Value
                End If
            End Set
        End Property

        Public Property POInOpera() As System.DateTime
            Get
                If Me.DataRow.IsPOInOperaNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.POInOpera
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetPOInOperaNull()
                Else
                    Me.DataRow.POInOpera = Value
                End If
            End Set
        End Property

        Public Property LagDays() As System.Int32
            Get
                If Me.DataRow.IsLagDaysNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.LagDays
                End If
            End Get
            Set(ByVal Value As System.Int32)
                If Value = Nothing Then
                    Me.DataRow.SetLagDaysNull()
                Else
                    Me.DataRow.LagDays = Value
                End If
            End Set
        End Property

        Public ReadOnly Property LagDaysIsNull() As Boolean
            Get
                Return Me.DataRow.IsLagDaysNull
            End Get
        End Property

        Public Property TargetETD() As System.DateTime
            Get
                If Me.DataRow.IsTargetETDNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.TargetETD
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetTargetETDNull()
                Else
                    Me.DataRow.TargetETD = Value
                End If
            End Set
        End Property

        Public Property OnHold() As System.Boolean
            Get
                If Me.DataRow.IsOnHoldNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.OnHold
                End If
            End Get
            Set(ByVal Value As System.Boolean)
                If Value = Nothing Then
                    Me.DataRow.SetOnHoldNull()
                Else
                    Me.DataRow.OnHold = Value
                End If
            End Set
        End Property

        Public Property ContainerDeliveried() As System.DateTime
            Get
                If Me.DataRow.IsContainerDeliveriedNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.ContainerDeliveried
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetContainerDeliveriedNull()
                Else
                    Me.DataRow.ContainerDeliveried = Value
                End If
            End Set
        End Property

        Public Property PayAuth() As System.String
            Get
                If Me.DataRow.IsPayAuthNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.PayAuth
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetPayAuthNull()
                Else
                    Me.DataRow.PayAuth = Value
                End If
            End Set
        End Property

        Public Property PDepValue() As System.Decimal
            Get
                If Me.DataRow.IsPDepValueNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.PDepValue
                End If
            End Get
            Set(ByVal Value As System.Decimal)
                If Value = Nothing Then
                    Me.DataRow.SetPDepValueNull()
                Else
                    Me.DataRow.PDepValue = Value
                End If
            End Set
        End Property

        Public ReadOnly Property IsPDepValueNull() As Boolean
            Get
                Return Me.DataRow.IsPDepValueNull
            End Get
        End Property

        Public Property SInvoiced() As System.Int32
            Get
                If Me.DataRow.IsSInvoicedNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.SInvoiced
                End If
            End Get
            Set(ByVal Value As System.Int32)
                If Value = Nothing Then
                    Me.DataRow.SetSInvoicedNull()
                Else
                    Me.DataRow.SInvoiced = Value
                End If
            End Set
        End Property


        Public ReadOnly Property IsSInvoicedNull() As Boolean
            Get
                Return Me.DataRow.IsSInvoicedNull
            End Get
        End Property

        Public Property SalesInvoiceValue() As System.Decimal
            Get
                If Me.DataRow.IsSalesInvoiceValueNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.SalesInvoiceValue
                End If
            End Get
            Set(ByVal Value As System.Decimal)
                If Value = Nothing Then
                    Me.DataRow.SetSalesInvoiceValueNull()
                Else
                    Me.DataRow.SalesInvoiceValue = Value
                End If
            End Set
        End Property

        Public ReadOnly Property IsSalesInvoiceValueNull() As Boolean
            Get
                Return Me.DataRow.IsSalesInvoiceValueNull
            End Get
        End Property

        Public Property SalesInvoiceDate() As System.DateTime
            Get
                If Me.DataRow.IsSalesInvoiceDateNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.SalesInvoiceDate
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetSalesInvoiceDateNull()
                Else
                    Me.DataRow.SalesInvoiceDate = Value
                End If
            End Set
        End Property

        Public ReadOnly Property IsSalesInvoiceDateNull() As Boolean
            Get
                Return Me.DataRow.IsSalesInvoiceDateNull
            End Get
        End Property

        Public Property SalesPaymentDue() As System.DateTime
            Get
                If Me.DataRow.IsSalesPaymentDueNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.SalesPaymentDue
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetSalesPaymentDueNull()
                Else
                    Me.DataRow.SalesPaymentDue = Value
                End If
            End Set
        End Property

        Public Property SInvoicedPd() As System.DateTime
            Get
                If Me.DataRow.IsSInvoicedPdNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.SInvoicedPd
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetSInvoicedPdNull()
                Else
                    Me.DataRow.SInvoicedPd = Value
                End If
            End Set
        End Property

        Public ReadOnly Property IsSalesPaymentDueNull() As Boolean
            Get
                Return Me.DataRow.IsSalesPaymentDueNull
            End Get
        End Property

        Public ReadOnly Property IsSInvoicedPdNull() As Boolean
            Get
                Return Me.DataRow.IsSInvoicedPdNull
            End Get
        End Property

        Public Property SuppOrderNo() As System.String
            Get
                If Me.DataRow.IsSuppOrderNoNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.SuppOrderNo
                End If
            End Get
            Set(ByVal Value As System.String)
                If Value = Nothing Then
                    Me.DataRow.SetSuppOrderNoNull()
                Else
                    Me.DataRow.SuppOrderNo = Value
                End If
            End Set
        End Property

        Public Property PayDate() As System.DateTime
            Get
                If Me.DataRow.IsSInvoicedPdNull Then
                    Return Nothing
                Else
                    Return Me.DataRow.PayDate
                End If
            End Get
            Set(ByVal Value As System.DateTime)
                If Value = Nothing Then
                    Me.DataRow.SetPayDateNull()
                Else
                    Me.DataRow.PayDate = Value
                End If
            End Set
        End Property

#End Region

    End Class

End Class

